/*
 * Copyright (C) 2008,2009,2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _ehash_h
#define _ehash_h

#include "etypes.h"

#define ehash_p(object)		(etype(object) == t_hash)
#define eentry_p(object)	(etype(object) == t_entry)

/*
 * Types
 */
struct eentry {
    eentry_t	*next;
    eobject_t	 value;
    eobject_t	 name;
    eint32_t	 key;
};

struct ehash {
    ehash_t	 *parent;		/* used for namespaces */
    eentry_t	**entries;		/* vector of entries */
    eint32_t	  size;			/* size of entries vector */
    eint32_t	  count;		/* sum of entries in vector */
    eint32_t	  offset;		/* used by external code */
    eint32_t	  memory	: 1;	/* compare memory contents? */
};

/*
 * Prototypes
 */
extern void
enew_hash(eobject_t *pointer, eint32_t mode, eint32_t size);

extern eint32_t
estr_hash(euint8_t *name, eint32_t length);

extern eentry_t *
eput_hash(ehash_t *hash, eentry_t *entry);

extern eentry_t *
eget_hash(ehash_t *hash, eobject_t name);

extern eentry_t *
eget_hash_entry(ehash_t *hash, eentry_t *entry);

extern eentry_t *
eget_hash_string(ehash_t *hash, euint8_t *name, eint32_t length);

extern eentry_t *
erem_hash(ehash_t *hash, eentry_t *entry);

extern void
eclr_hash(ehash_t *hash);

extern void
erehash(ehash_t *hash);

extern void
init_hash(void);

/*
 * Externs
 */
extern ehash_t *ht_root;	/* root namespace */
extern ehash_t *ht_current;	/* current namespace */
extern ehash_t *ht_language;	/* language&scratch namespace */

#endif /* _ehash_h */
